<?php
/*
 * @Description    : 短信发送
 * @Author         : QianLong
 * @Date           : 2023-01-11 12:13:55
 * @LastEditors    : QianLong
 * @Site           : http://21ds.cn
 * @LastEditTime   : 2023-04-10 12:17:17
 */

declare(strict_types=1);

namespace App\Controller;

use App\Constants\Status;
use App\Exception\ApiException;
use App\Service\Common;
use Qianlong\Validate\Validate;

class IpController extends AbstractController
{
  public function search()
  {
    $valitor = new Validate();
    $valitor->addColumn('ip')->required();
    if ($valitor && !$this->validate($valitor)) {
      throw new ApiException(Status::CODE_BAD_REQUEST, $valitor->getError()->__toString());
    }
    unset($valitor);
    $param = $this->request->all();
    $regionStr = (new Common)->ip2Region($param['ip']);
    return $this->response->json(Status::CODE_OK, 'success', $regionStr);
  }
}
